import java.util.Enumeration;
import java.util.Vector;

/**
 * Created by Administrator on 2016/4/5.
 */
public class Customer {
    private String name;
    private Vector rentals = new Vector();

    public Customer(String name) {
        this.name = name;
    }

    public String statement() {

        int frequentRenterPoints = 0;
        Enumeration rentalsElem = rentals.elements();
        String result = "Rental Record for " + getName() + "\n";
        while (rentalsElem.hasMoreElements()) {
            Rental each = (Rental) rentalsElem.nextElement();
            frequentRenterPoints = each.getFrequentRenterPoints();
            //show figures for this rental
            result += "\t" + each.getMovie().getTitle() + "\t" + each.getCharge();
        }
        //add footer lines
        result += "Amount owed is " + getTotalCharge() + "\n";
        result += "You earned " + getTotalFrequentRenterPoints() + " frequent renter points";
        return result;
    }

    private double getTotalCharge() {
        double totalAmount = 0;
        Enumeration rentalsElem = rentals.elements();
        while (rentalsElem.hasMoreElements()) {
            Rental each = (Rental) rentalsElem.nextElement();
            totalAmount += each.getCharge();
        }
        return totalAmount;
    }
    private int getTotalFrequentRenterPoints() {
        int result = 0;
        Enumeration rentalsElem = rentals.elements();
        while (rentalsElem.hasMoreElements()) {
            Rental each = (Rental) rentalsElem.nextElement();
            result += each.getFrequentRenterPoints();
        }
        return result;
    }


    private double amountFor(Rental aRental) {
        return aRental.getCharge();
    }

    public void addRental(Rental rental) {
        rentals.add(rental);
    }

    public String getName() {
        return name;
    }
}
